package com.androidx.p013lv.base.utils;

import android.graphics.Bitmap;
import android.text.TextUtils;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.RGBLuminanceSource;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.common.StringUtils;
import com.google.zxing.qrcode.QRCodeReader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Hashtable;

/* renamed from: com.androidx.lv.base.utils.QRHelper */
public class QRHelper {
    public static String getResult(Bitmap bitmap) {
        String scanBitmap = bitmap != null ? scanBitmap(bitmap) : null;
        if (!TextUtils.isEmpty(scanBitmap)) {
            return scanBitmap;
        }
        return null;
    }

    private static String scanBitmap(Bitmap bitmap) {
        Result scan = scan(bitmap);
        if (scan != null) {
            return recode(scan.toString());
        }
        return null;
    }

    private static String recode(String str) {
        try {
            if (StandardCharsets.ISO_8859_1.newEncoder().canEncode(str)) {
                return new String(str.getBytes(StandardCharsets.ISO_8859_1), StringUtils.GB2312);
            }
            return str;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return "";
        }
    }

    private static Result scan(Bitmap bitmap) {
        Hashtable hashtable = new Hashtable();
        hashtable.put(DecodeHintType.CHARACTER_SET, "utf-8");
        Bitmap createBitmap = Bitmap.createBitmap(bitmap);
        int[] iArr = new int[(createBitmap.getWidth() * createBitmap.getHeight())];
        createBitmap.getPixels(iArr, 0, createBitmap.getWidth(), 0, 0, createBitmap.getWidth(), createBitmap.getHeight());
        try {
            return new QRCodeReader().decode(new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(createBitmap.getWidth(), createBitmap.getHeight(), iArr))), hashtable);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
